package com.jiang.专题.双指针.Q202;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/03/18 21:24
 */
class Solution {
    public boolean isHappy(int n) {
        int slow = n, fast = n;
        do {
            slow = isHappyNum(slow);
            fast = isHappyNum(fast);
            fast = isHappyNum(fast);
        } while (slow != fast);
        return slow == 1;
    }

    public int isHappyNum(int n) {
        int sum = 0;
        while (n > 0) {
            int t = n % 10;
            sum += t * t;
            n /= 10;
        }
        return sum;
    }
}
